﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using UTC_Project_Manager.Model.Infrastructure;

namespace UTC_Project_Manager.Converters
{
    public class DatesConverter : IValueConverter
    {
        static DatesConverter()
        {
            DateTime start = App.MyConfig.OurProject.StartDate;
            DateTime end = App.MyConfig.OurProject.EndDate;

            if (!start.Equals(DateTime.Parse("01/01/0001 00:00:00")) && !end.Equals(DateTime.Parse("01/01/0001 00:00:00")))
            {
                App.MyConfig.dict.Add(start, "Début du projet");
                App.MyConfig.dict.Add(end, "Fin du projet");
            }

            foreach (Meeting meeting in App.MyConfig.OurProject.Meetings)
            {
                DateTime date = new DateTime(meeting.Date.Year, meeting.Date.Month, meeting.Date.Day);
                if (App.MyConfig.dict.ContainsKey(date)) 
                    App.MyConfig.dict[date] += "\n" + "[" + meeting.Date.TimeOfDay + "] " + meeting.Title;
                else
                    App.MyConfig.dict.Add(date, "[" + meeting.Date.TimeOfDay + "] " + meeting.Title);
            }

            
        }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string text = "";
            try
            {
                if (!App.MyConfig.dict.TryGetValue((DateTime)value, out text))
                    text = null;
            }
            catch (Exception e) { }
            return text;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }
}

